import { defineStore } from 'pinia';
// 定义一个唯一的store id，用于区分不同的store
export const useCounterStore = defineStore('counter', {
    state: () => ({
        arr: [],
        arrzan: [],
        userInfo: {
            name: 'John',
            age: 30,
        },
        tokens: ['token1', 'token2']
    }),
    actions: {
        // 收藏
        add(newItem) {
            if (!this.arr.includes(newItem)) {
                this.arr.push(newItem)
            } else {
                console.log('重复了')
            }
        },
        // 点赞
        addzan(newItem) {
            if (!this.arrzan.includes(newItem)) {
                this.arrzan.push(newItem)
            } else {
                console.log('重复了')
            }
        },
    },
    // 配置持久化
    persist: {
        enabled: true,
        strategies: [
            {
                key: 'my_store_key',
                storage: localStorage
            }
        ]
    }
})
